#include "debug.h"
#include <tchar.h>
#include <SDL/SDL_ttf.h>
#include <algorithm>
#include "Utils\\Font.h"

NS_BEGIN(SDL)
NS_BEGIN(UTILS)

tRenderSolidBlended const Font::RenderSolid = TTF_RenderUNICODE_Solid;
tRenderSolidBlended const Font::RenderBlended = TTF_RenderUNICODE_Blended;
tRenderShaded const Font::RenderShaded = TTF_RenderUNICODE_Shaded;

#pragma region CTOR & DTOR

Font::Font(std::string const& _path, int _size, int _style)
	: m_path(_path), m_font(NULL)
{
	CTOR("Font", this);
	m_font = TTF_OpenFont(_path.c_str(), _size);
	TTF_SetFontStyle(m_font, _style);
}

Font::Font(Font const&)
{
}

Font::~Font()
{
	DTOR("Font", this);
	TTF_CloseFont(m_font);
}

#pragma endregion
#pragma region Operators

Font& Font::operator=(Font const&)
{
	return (*this);
}

#pragma endregion

int Font::CalculWidth(std::string const& _text) const
{
	int w = 0, h = 0;
	TTF_SizeText(m_font, _text.c_str(), &w, &h);
	return (w);
}

std::wstring Font::StringToWString(std::string const& _s)
{
	std::wstring tmp(_s.length(), L' ');
	std::copy(_s.begin(), _s.end(), tmp.begin());
	return (tmp);
}


std::string Font::WStringToString(std::wstring const& _s)
{
	std::string tmp(_s.length(), ' ');
	std::copy(_s.begin(), _s.end(), tmp.begin());
	return (tmp);
}

#pragma region Getters & Setters

std::string const& Font::GetPath() const
{
	return (m_path);
}

TTF_Font* Font::GetFont() const
{
	return (m_font);
}

int Font::GetSize() const
{
	int w = 0, h = 0;
	TTF_SizeText(m_font, "A", &w, &h);
	return (h);
}

int Font::GetStyle() const
{
	return (TTF_GetFontStyle(m_font));
}

#pragma endregion

NS_END(UTILS)
NS_END(SDL)
